let id = getCookie('id');

console.log(id);
pAjax({
    // https://wx.maoyan.com/mmdb/movie/v5/1298311.json?ci=20
    url: `/dai/movie/v5/${id}.json`,
    data: {
        ci:20,
    }
}).then(res => {
    res = JSON.parse(res);
    console.log(res);
    res.data.movie.img = res.data.movie.img.replace('/w.h', '');
    
    // 片名渲染
    let str = '';
    str += `
    <div class="topLf">
    <img src="${res.data.movie.img}" alt="">
    </div>
    <div class="topright">
    <h4>${res.data.movie.nm}</h4>
    <i>${res.data.movie.wish}人想看</i>
    <p>${res.data.movie.cat}</p>
    <p>中国大陆/91分钟</p>
    <p>${res.data.movie.pubDesc}</p>
    </div>
    <div class="topbottom">
    <button><span></span> 想看</button>
    <button><span></span> 评分</button>
</div>
    `;
    $('.top').html(str);

    // toptwo渲染
    let str1 = '';
    str1 += `
    <p>
    ${res.data.movie.dra}
    </p>
<i></i>
    `;
    $('.toptwo').html(str1);


    // 视频和剧照
    let str4 = '';
    // console.log(res.data.movie.photos);
    res.data.movie.photos.forEach(item => {
        item = item.replace('/w.h', '');
        str4 += `
        <img src="${item}" alt="">
        `;
    });
    $('.videoul').html(str4);
    $('.videonumber').text(res.data.movie.photos.length);
});

$('.boxback').click(function () {
    let u = localStorage.getItem('url');
    location.href = u;
})

// 演员渲染
let actorul = document.querySelector('.actorul');
pAjax({
    // https://wx.maoyan.com/mmdb/v7/movie/1351039/celebrities.json
    url: `/dai/v7/movie/${id}/celebrities.json`,
}).then(res => {
    res = JSON.parse(res);
    console.log(res);
    let str2 = '';
    // console.log(res.data[0]);
    res.data[0].forEach(item => {
        item.avatar= item.avatar.replace('/w.h', '');
        str2 += `
        <li>
        <img src="${item.avatar}" alt="">
        <h5>${item.cnm}</h5>
        <p>${item.desc}</p>
        </li>
        `;
    });
    actorul.innerHTML += str2;

    // console.log(res.data[1]);
    let str3 = '';
    res.data[1].forEach(item => {
        item.avatar= item.avatar.replace('/w.h', '');
        str3+= `
        <li>
        <img src="${item.avatar}" alt="">
        <h5>${item.cnm}</h5>
        <p>${item.desc}</p>
        </li>
        `;
    });
    actorul.innerHTML += str3;
});


// 评论渲染
pAjax({
    // https://wx.maoyan.com/mmdb/comments/movie/v2/1351039.json?limit=3&offset=0&uuid=1A6E888B4A4B29B16FBA1299108DBE9C25451D87F2A6D22D0F67C5092D7994D0&token=&ci=20&clientType=wechat_small_program&channelId=40000
    url: `/dai/comments/movie/v2/${id}.json`,
    data: {
        limit:3,
        offset:0,
        uuid:'1A6E888B4A4B29B16FBA1299108DBE9C25451D87F2A6D22D0F67C5092D7994D0' ,
        // token:,
        ci:20,
        clientType:'wechat_small_program',
        channelId:40000,
    }
}).then(res => {
    res = JSON.parse(res);
    console.log(res);
    console.log('评论数据');
});